<template>
	<view class="content">
		<view class="title">
			<view class="register">
				<image src="../../../static/logo@2x.png" mode=""></image>
				<input class="phone" maxlength="11" placeholder="在这里输入您的手机号码" v-model="mobile" />
				<input class="phone" maxlength="10" type="password" placeholder="在这里输入您的密码" v-model="password" />
				<input class="phone" maxlength="10" type="password" placeholder="请再次确认一遍密码" v-model="password_confirm" />
				<u-form-item :label-position="labelPosition" label="验证码" prop="code" label-width="100" class="froms">
					<u-input :border="border" placeholder="请输入验证码" v-model="verify_code" type="text"></u-input>
					<u-button slot="right" type="success" size="mini" @click="getCode">{{codeTips}}</u-button>
				</u-form-item>
				<input class="phone" maxlength="10" placeholder="邀请码"  v-model="invite_code" />
				<u-form-item :label-position="labelPosition" label="所在地区" prop="region" label-width="150" class="froms">
					<u-input :border="border" type="select" :select-open="pickerShow" v-model="model.region"
						placeholder="请选择地区" @click="pickerShow = true"></u-input>
				</u-form-item>
				<button class="bt2" type="default" @click="gogogo">注册</button>
				<u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
			</view>
		</view>
		<u-picker mode="region" v-model="pickerShow" @confirm="regionConfirm" class="froms"></u-picker>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				title: '注册',
				labelPosition: 'left',
				model: {
					code: '',
					region: '',
				},
				codeTips: '',
				border: false,
				pickerShow: false,
				mobile: "", //电话号码
				password: "", //密码
				password_confirm: "", //确认密码
				verify_code: "", //短信验证码
				invite_code: "", //邀请码
				source: "1"
			}
		},
		components: {

		},
		onLoad() {

		},
		methods: {
			// 选择地区回调
			regionConfirm(e) {
				this.model.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
			},
			labelPositionChange(index) {
				this.labelPosition = index == 0 ? 'left' : 'top';
			},
			codeChange(text) {
				this.codeTips = text;
			},
			getCode() {
				let data={
					mobile:this.mobile
				}
				this.$api.code(data).then(res => {
					console.log(res)
				}, err => {
					
				})
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码',
						mask: true
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						this.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			gogogo() {
				let data = {
					mobile:this.mobile,
					password:this.password,
					password_confirm:this.password_confirm,
					verify_code:this.verify_code,
					invite_code:this.invite_code,
					source:this.source
				}
				this.$api.register(data).then(res => {
					this.$common.successToShow(res.data.msg,()=>{})
					if (res.data.msg==="注册成功") {
						this.$common.successToShow(res.data.msg,()=>{
							uni.redirectTo({
							    url: '../login/index'
							});
						})
					}
				}, err => {})
			}
		}
	}
</script>
<style lang="less">
	.content {
		background-image: url(../../../static/img-d.png);
		width: 750rpx;
		height: 1334rpx;
		background-size: cover;
		background-repeat: no-repeat;

		.title {
			background-image: url(../../../static/img_t.png);
			background-size: cover;
			background-repeat: no-repeat;
			width: 750rpx;
			height: 478rpx;
			position: relative;

			.register {
				width: 560rpx;
				height: 1040rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				position: absolute;
				left: 50%;
				transform: translate(-50%, 15%);
				text-align: center;
				padding: 66rpx 40rpx 0 40rpx;

				image {
					width: 156rpx;
					height: 184rpx;
				}

				.phone {
					text-align: left;
					width: 100%;
					border-bottom: 1px solid #D2D2D2;
					margin-top: 20rpx;
					font-size: 24rpx;
					color: #C1C1C1;
					height: 80rpx;
				}

				.bt1 {
					margin-top: 40rpx;
					height: 78rpx;
					background: linear-gradient(77deg, #4E7BFA 0%, #764CFA 100%);
					font-size: 28rpx;
					color: #FFFFFF;
					line-height: 78rpx;
				}

				.bt2 {
					margin-top: 40rpx;
					height: 78rpx;
					border: 1px solid #764CFA;
					opacity: 1;
					border-radius: 4px;
					color: #764CFA;
					font-size: 28rpx;
					line-height: 78rpx;
				}

				.froms {
					color: #808080;
				}
			}
		}
	}
</style>
